#coding=utf8
#!/usr/bin/python
# -*- coding: utf-8 -*-

from treelib import Node, Tree
from collections import deque


def borderFirstSearch(tree):
    '''
    广度优先
    :param tree:
    :return:
    '''
    print '广度优先'
    print(','.join([tree[node].tag for node in \
                    tree.expand_tree(mode=Tree.WIDTH)]))

def depthFirstSearch(tree):
    '''
        深度优先
        :param tree:
        :return:
        '''
    print '深度优先'
    print(','.join([tree[node].tag for node in \
                    tree.expand_tree(mode=Tree.DEPTH)]))


if __name__ == "__main__":
    tree = Tree()
    tree.create_node("Harry", "harry")  # root node
    tree.create_node("Jane", "jane", parent="harry")
    tree.create_node("Bill", "bill", parent="harry")
    tree.create_node("Mike", "mike", parent="harry")
    tree.create_node("Diane", "diane", parent="jane")
    tree.create_node("Mary", "mary", parent="diane")
    tree.create_node("Mark", "mark", parent="jane")

    tree.show()
    borderFirstSearch(tree)
    depthFirstSearch(tree)



